package com.slz3.business.module.configManagement.conZoneManage.steward;

import com.slz3.business.frame.module.Services;
import com.slz3.business.frame.util.VE;
import com.slz3.business.module.configManagement.conZoneManage.domain.ConZoneManage;
import com.slz3.business.module.drawManagement.draFreeLottery.domain.DraFreeLottery;
import com.slz3.business.module.drawManagement.draIntegralLottery.domain.DraIntegralLottery;
import com.slz3.business.module.goodsManagement.gooGoods.domain.GooGoods;
import com.slz3.business.module.socialManagement.socArticle.domain.SocArticle;

import java.math.BigDecimal;
import java.util.Optional;

public class ConZoneManageSteward {

    public static void redundancy(ConZoneManage conZoneManage) {
        // goods info
        Long fkGoodsIncrementId = null;
        String serGoodsName = null;
        String serGoodsPrice = null;
        if (VE.isNotEmptyArr(conZoneManage.getSerGoodsTypeFlag(), conZoneManage.getFkGoods())) {
            switch (conZoneManage.getSerGoodsTypeFlag()) {
                case CASH:
                case INTEGRAL:
                    GooGoods goods = Services.gooGoods.single(conZoneManage.getFkGoods()).get();
                    fkGoodsIncrementId = goods.getIncrementId();
                    serGoodsName = goods.getSerGoodsName();
                    serGoodsPrice = Optional.ofNullable(goods.getSerGoodsPricel()).orElse(BigDecimal.ZERO).toString(); // 要现价
                    break;
                case DRAW_FREE:
                    DraFreeLottery free = Services.draFreeLottery.single(conZoneManage.getFkGoods()).get();
                    fkGoodsIncrementId = free.getIncrementId();
                    serGoodsName = free.getSerGoodsDrawName();
                    serGoodsPrice = free.getSerGoodsDrawPrice();
                    break;
                case DRAW_INTEGRAL:
                    DraIntegralLottery integral = Services.draIntegralLottery.single(conZoneManage.getFkGoods()).get();
                    fkGoodsIncrementId = integral.getIncrementId();
                    serGoodsName = integral.getSerGoodsDrawName();
                    serGoodsPrice = Optional.ofNullable(integral.getSerGoodsDrawPrice()).orElse(BigDecimal.ZERO).toString();
                    break;
                case ARTICLE:
                    SocArticle article = Services.socArticle.single(conZoneManage.getFkGoods()).get();
                    fkGoodsIncrementId = article.getIncrementId();
                    serGoodsName = article.getSerTheme();
                    serGoodsPrice = "999999";
                    break;
            }
        }
        conZoneManage.setFkGoodsIncrementId(fkGoodsIncrementId);
        conZoneManage.setSerGoodsName(serGoodsName);
        conZoneManage.setSerGoodsPrice(serGoodsPrice);
    }

}
